//display pv digits
var pseg_0 = new Image();
pseg_0.src = "pngs/seg_0.png";
var pseg_1 = new Image();
pseg_1.src = "pngs/seg_1.png";
var pseg_2 = new Image();
pseg_2.src = "pngs/seg_2.png";
var pseg_3 = new Image();
pseg_3.src = "pngs/seg_3.png";
var pseg_4 = new Image();
pseg_4.src = "pngs/seg_4.png";
var pseg_5 = new Image();
pseg_5.src = "pngs/seg_5.png";
var pseg_6 = new Image();
pseg_6.src = "pngs/seg_6.png";
var pseg_7 = new Image();
pseg_7.src = "pngs/seg_7.png";
var pseg_8 = new Image();
pseg_8.src = "pngs/seg_8.png";
var pseg_9 = new Image();
pseg_9.src = "pngs/seg_9.png";
//end pv dsp preload
//display sp digits
var sseg_0 = new Image();
sseg_0.src = "pngs/dig_0.png";
var sseg_1 = new Image();
sseg_1.src = "pngs/dig_1.png";
var sseg_2 = new Image();
sseg_2.src = "pngs/dig_2.png";
var sseg_3 = new Image();
sseg_3.src = "pngs/dig_3.png";
var sseg_4 = new Image();
sseg_4.src = "pngs/dig_4.png";
var sseg_5 = new Image();
sseg_5.src = "pngs/dig_5.png";
var sseg_6 = new Image();
sseg_6.src = "pngs/dig_6.png";
var sseg_7 = new Image();
sseg_7.src = "pngs/dig_7.png";
var sseg_8 = new Image();
sseg_8.src = "pngs/dig_8.png";
var sseg_9 = new Image();
sseg_9.src = "pngs/dig_9.png";
//end pv dsp preload
var colon_1 = new Image();
colon_1.src = "pngs/colon_on.png";
var colon_0 = new Image();
colon_0.src = "pngs/colon_off.png";
//
var sp_0 = 0;
var sp_1 = 0;
//
var status_time;
var time_now;
var day_now ;
var month_now ;
var year_now ;
var hours_now;
var mins_now;
var secs_now;
var msec_now;
var wday_now;
var week_day;
var curr_month;
var week_num;
var day_lite;
//
var base_time=1000;
var up;
var min1=0;
var min2=0;
var hur1=0;
var hur2=0;
//
//
function show_clock(){
day_lite = document.getElementById('day-led');
dsp_test();
}
//
function dsp_test(){
document.images.pvdsp4.src = pseg_8.src;
document.images.pvdsp3.src = pseg_8.src;
document.images.pvdsp2.src = pseg_8.src;
document.images.pvdsp1.src = pseg_8.src;
document.images.spdsp1.src = sseg_8.src;
document.images.spdsp0.src = sseg_8.src;
document.images.dtdsp1.src = sseg_8.src;
document.images.dtdsp2.src = sseg_8.src;
document.images.dtdsp3.src = sseg_8.src;
document.images.dtdsp4.src = sseg_8.src;
document.images.dtdsp5.src = sseg_8.src;
document.images.dtdsp6.src = sseg_8.src;
document.images.wkdsp1.src = sseg_8.src;
document.images.wkdsp0.src = sseg_8.src;
document.images.colon_sec.src = colon_1.src;
window.setTimeout("dsp_rst();",2000);
}
//
function dsp_rst(){
document.images.pvdsp4.src = pseg_0.src;
document.images.pvdsp3.src = pseg_0.src;
document.images.pvdsp2.src = pseg_0.src;
document.images.pvdsp1.src = pseg_0.src;
document.images.spdsp1.src = sseg_0.src;
document.images.spdsp0.src = sseg_0.src;
document.images.dtdsp1.src = sseg_0.src;
document.images.dtdsp2.src = sseg_0.src;
document.images.dtdsp3.src = sseg_0.src;
document.images.dtdsp4.src = sseg_0.src;
document.images.dtdsp5.src = sseg_0.src;
document.images.dtdsp6.src = sseg_0.src;
document.images.wkdsp1.src = sseg_0.src;
document.images.wkdsp0.src = sseg_0.src;
document.images.colon_sec.src = colon_0.src;
window.setTimeout("clock_start();",1000);
}
//
//
//date-time
//
function get_time() {
time_now = new Date();
wday_now = time_now.getDay() + 1;
msec_now = time_now.getTime();
day_now = time_now.getDate();
month_now = time_now.getMonth() + 1;
year_now = time_now.getFullYear();
hours_now = time_now.getHours();
mins_now = time_now.getMinutes();
secs_now = time_now.getSeconds();
if (mins_now < 10)
{
min1 = mins_now;
min2 = 0;
}
else
{
min2 = parseInt(mins_now/10);
min1 = mins_now - (min2 * 10);
}
if (secs_now < 10)
{
sp_0 = secs_now;
sp_1 = 0;
}
else
{
sp_1 = parseInt(secs_now/10);
sp_0 = secs_now - (sp_1 * 10);
}
if (hours_now < 10 && hours_now > 0 )
{
hur1 = hours_now;
hur2 = 0;
}
else
{
hur2 = parseInt(hours_now/10);
hur1 = hours_now - (hur2 * 10);
}
//week days
switch(wday_now){
case 1:
day_lite.style.left = 160;
break;
case 2:
day_lite.style.left = 30;
break;
case 3:
day_lite.style.left = 52;
break;
case 4:
day_lite.style.left = 74;
break;
case 5:
day_lite.style.left = 98;
break;
case 6:
day_lite.style.left = 118;
break;
case 7:
day_lite.style.left = 140;
break;
}
//
day_lite.style.background = "#FF5959";
//
get_wn();
//
update_digits();
}
//
// adapted from week number  www.quirksmode.org/js/week.html
function get_wn() {
 	var today = new Date();
	Year = takeYear(today);
	Month = today.getMonth();
	Day = today.getDate();
	now = Date.UTC(Year,Month,Day+1,0,0,0);
	var Firstday = new Date();
	Firstday.setYear(Year);
	Firstday.setMonth(0);
	Firstday.setDate(1);
	then = Date.UTC(Year,0,1,0,0,0);
	var Compensation = Firstday.getDay();
	if (Compensation > 3) Compensation -= 4;
	else Compensation += 3;
	week_num =  Math.round((((now-then)/86400000)+Compensation)/7);
}
//
//
function takeYear(theDate)
{
 x = theDate.getYear();
 var y = x % 100;
 y += (y < 38) ? 2000 : 1900;
 return y;
}
//  quirksmode week end
//
//
//1 Sec Clock timer
function clock_start() {
document.images.colon_sec.src = colon_1.src;
up=setTimeout("colon_off();",(base_time/2));
}
function colon_off() {
document.images.colon_sec.src = colon_0.src;
up=setTimeout("clock_start();",(base_time/2));
get_time();
}
//end sec clock
//
var wek_str="";
//
//display sp
function dsp_sp() {
document.images.spdsp0.src = "pngs/dig_" + sp_0 + ".png";
document.images.spdsp1.src = "pngs/dig_" + sp_1 + ".png";
//
if(week_num>9){wek_str = "h"+ week_num;}
else{wek_str = "h0"+ week_num;}
document.images.wkdsp0.src = eval("sseg_" + wek_str.charAt(2) + ".src");
document.images.wkdsp1.src = eval("sseg_" + wek_str.charAt(1) + ".src");
}
//
var day_str="";
var mon_str="";
var yer_str="";
//display pv
function dsp_pv() {
document.images.pvdsp1.src = "pngs/seg_" + min1 + ".png";
document.images.pvdsp2.src = "pngs/seg_" + min2 + ".png";
document.images.pvdsp3.src = "pngs/seg_" + hur1 + ".png";
document.images.pvdsp4.src = "pngs/seg_" + hur2 + ".png";
//
if(day_now>9){day_str = "h"+ day_now;}
else{day_str = "h0"+ day_now;}
//
document.images.dtdsp5.src = eval("sseg_" + day_str.charAt(2) + ".src");
document.images.dtdsp6.src = eval("sseg_" + day_str.charAt(1) + ".src");
//
if(month_now>9){mon_str = "h"+ month_now;}
else{mon_str = "h0"+ month_now;}
//
document.images.dtdsp3.src = eval("sseg_" + mon_str.charAt(2) + ".src");
document.images.dtdsp4.src = eval("sseg_" + mon_str.charAt(1) + ".src");
//
yer_str = "h"+ year_now;
document.images.dtdsp1.src = eval("sseg_" + yer_str.charAt(4) + ".src");
document.images.dtdsp2.src = eval("sseg_" + yer_str.charAt(3) + ".src");
}
//
function update_digits() {
dsp_sp();
dsp_pv();
}
//
window.onload=show_clock;
//
//end of script